;-------------------------------------------------------------LICENSE--------------------------------------------------------------;
;                                                                                                                                  ;
;The MAP code is written in Fortran language for magnetohydrodynamics (MHD) calculation with the adaptive mesh refinement (AMR)    ;
;and Message Passing Interface (MPI) parallelization.                                                                              ;
;                                                                                                                                  ;
;Copyright (C) 2012                                                                                                                ;
;Ronglin Jiang                                                                                                                     ;
;rljiang@ssc.net.cn                                                                                                                ;
;585 Guoshoujing Road. Pudong, Shanghai, P.R.C. 201203                                                                             ;
;                                                                                                                                  ;
;This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License         ;
;as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.             ;
;                                                                                                                                  ;
;This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of    ;
;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more details.                        ;
;                                                                                                                                  ;
;You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software     ;
;Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.                                                   ;
;                                                                                                                                  ;
;-------------------------------------------------------------LICENSE--------------------------------------------------------------;

pro rdpr_map_3d, par, datavis_path, info_name

   close, /all
   cd, datavis_path, current = old_dir

   output_real8_flag = 0l & cpu_number = 0l & n_dims = 0l & sys = 0l & ng = 0l
   ini_block_x = 0l & ini_block_y = 0l & ini_block_z = 0l
   nx = 0l & ny = 0l & nz = 0l
   ratio = 0l & n_levels = 0l
   gm = 0.0d0 & cfl = 0.0d0 & rangex = 0.0d0 & rangey = 0.0d0 & rangez = 0.0d0
   zero_posx = 0.0d0 & zero_posy = 0.0d0 & zero_posz = 0.0d0
   nt = 0l & n_var = 0l

   endian = 0
   catch, bad_endian

   if bad_endian ne 0 then begin
      print, '|----Swap endian----|'
      endian = 1
      close, /all
   endif

   openr, unit, info_name, /get_lun, swap_endian = endian, /f77_unformatted
   readu, unit, output_real8_flag
   readu, unit, cpu_number
   readu, unit, n_dims
   readu, unit, sys
   readu, unit, ng
   readu, unit, ini_block_x
   readu, unit, ini_block_y
   readu, unit, ini_block_z
   readu, unit, nx
   readu, unit, ny
   readu, unit, nz
   readu, unit, ratio
   readu, unit, n_levels
   readu, unit, gm
   readu, unit, rangex
   readu, unit, rangey
   readu, unit, rangez
   readu, unit, zero_posx
   readu, unit, zero_posy
   readu, unit, zero_posz
   readu, unit, cfl
   readu, unit, nt
   t = dblarr(nt) & dt = dblarr(nt) & n_blocks_all = lonarr(nt)
   readu, unit, t
   readu, unit, dt
   readu, unit, n_blocks_all
   readu, unit, n_var
   var_name = bytarr(128, n_var)
   if output_real8_flag eq 4 then begin
      var_min = fltarr(n_var)
      var_max = fltarr(n_var)
   endif else begin
      var_min = dblarr(n_var)
      var_max = dblarr(n_var)
   endelse
   var_dim = lonarr(n_var)
   readu, unit, var_name
   var_name = strcompress(string(var_name), /remove_all)
   readu, unit, var_max
   readu, unit, var_min
   readu, unit, var_dim
   close, unit
   free_lun, unit

   catch, /cancel

   par = {output_real8_flag : output_real8_flag,                                                                                   $
      cpu_number : cpu_number,                                                                                                     $
      n_dims : n_dims,                                                                                                             $
      sys : sys,                                                                                                                   $
      ng : ng,                                                                                                                     $
      ini_block_x : ini_block_x,                                                                                                   $
      ini_block_y : ini_block_y,                                                                                                   $
      ini_block_z : ini_block_z,                                                                                                   $
      nx : nx,                                                                                                                     $
      ny : ny,                                                                                                                     $
      nz : nz,                                                                                                                     $
      ratio : ratio,                                                                                                               $
      n_levels : n_levels,                                                                                                         $
      gm : gm,                                                                                                                     $
      rangex : rangex,                                                                                                             $
      rangey : rangey,                                                                                                             $
      rangez : rangez,                                                                                                             $
      zero_posx : zero_posx,                                                                                                       $
      zero_posy : zero_posy,                                                                                                       $
      zero_posz : zero_posz,                                                                                                       $
      cfl : cfl,                                                                                                                   $
      nt : nt,                                                                                                                     $
      t : t,                                                                                                                       $
      dt : dt,                                                                                                                     $
      n_blocks_all : n_blocks_all,                                                                                                 $
      n_var : n_var,                                                                                                               $
      var_name : var_name,                                                                                                         $
      var_max : var_max,                                                                                                           $
      var_min : var_min,                                                                                                           $
      var_dim : var_dim                                                                                                            $
      }

   cd, old_dir

end
